package com.culture.config.wrapper;

import java.util.Date;
import java.util.List;

import com.culture.config.dao.entity.JobInfo;
import com.culture.config.dao.entity.JobLog;
import com.culture.config.model.po.JobLogPagePO;
import com.culture.config.util.AuthenticationUtil;

import org.apache.commons.collections4.CollectionUtils;

import lombok.experimental.UtilityClass;

@UtilityClass
public class JobLogWrapper {  

    public JobLog wrapJobLogQeury(JobLogPagePO jobLogPagePO){
        JobLog jobLogQuery = new JobLog(jobLogPagePO.getJobId());
        jobLogQuery.setScheduleTime(jobLogPagePO.getScheduleTime());
        return jobLogQuery;
    }

    public JobLog wrapJobLogAdd(JobInfo jobInfo,String result){
        JobLog jobLog = new JobLog(jobInfo.getId());
        jobLog.setScheduleTime(new Date());
        jobLog.setScheduleResult(result);
        AuthenticationUtil.setInsertFieldInfo(jobLog);
        return jobLog;
    }

    public JobLog wrapJobLogClear(JobInfo jobInfo,List<JobLog> topList){
        JobLog jobLog = new JobLog(jobInfo.getId());      
        if(CollectionUtils.isNotEmpty(topList)){
            jobLog.setId(topList.get(topList.size() -1).getId());
        }
        return jobLog;
    }
    
    
}
